/*************************Copyright (c)*************************
 

**--------------------------File Info---------------------------

** File name:
** Last modified Date:

** Last Version:

** Descriptions:
**---------------------------------------------------------------

** Created by:		刘家辉 
** Created date:	2021/01/08

** Version:			V1.0
** Descriptions:	回调函数学习记录
** Notes:           gcc func_pointer.c ku.c ku.h
                    ./a.out          
** Tips:            
**---------------------------------------------------------------
*/

#include <stdio.h>
#include "ku.h"

// 不带参数的函数回调
int Handle_1(int (*Callback)(void));
int callback_1(void);

// 带参数的函数回调
int Handle_2(int count,int (*Callback)(int));
int callback_2(int count);


int main(void)
{
    int a = 5;

    Handle_1(callback_1);//这里把我们实现的回调函数也就是callback_1当作指针传入
    printf("\r\n");
    Handle_2(a, callback_2);//这里把我们实现的回调函数也就是callback_2当作指针传入
    printf("\r\n");
    Handle_3(a,callback_2);
    return 0;
}

int Handle_1(int (*Callback)(void))
{
    printf("Entering Handle_1 function... <Handle_1>\n");

    //这里调用callback函数指针，这个动作就叫做回调
    printf("回调函数的返回值为:%d\n", Callback());

    printf("Leaving Handle_1 function... <Handle_1>\n");
}

int callback_1(void)
{
    printf("hello <callback_1>\n");
    return 1;
}


int Handle_2(int count,int (*Callback)(int))
{
    printf("Entering Handle_2 function... <Handle_2>\n");

    //这里调用callback函数指针，这个动作就叫做回调
    printf("回调函数的返回值为:%d\n", Callback(count));

    printf("Leaving Handle_2 function... <Handle_2>\n");
}

int callback_2(int count)
{
    printf("hello,my count :%d <callback_2>\n", count);
    return count;
}
